package com.wangzh.concurrent.lock.blockingqueue;

import java.util.ArrayList;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;


public class BlockingQueueTest {
    public static void main(String[] args) throws InterruptedException {

        test3();
    }

//    阻塞
    private static void test3() throws InterruptedException {
        //一直等待
        BlockingQueue queue = new ArrayBlockingQueue(3);
        queue.put("A");
        queue.put(1);
        queue.put(1);
        queue.put(1);

        System.out.println(queue.take());
        System.out.println(queue.take());
        System.out.println(queue.take());
//        System.out.println(queue.take());
    }
    private static void test2() {
        //抛出false
        BlockingQueue queue = new ArrayBlockingQueue(3);
        queue.offer("A");
        queue.offer(1);
        System.out.println(queue.offer(1));

        System.out.println(queue.offer(1));

        System.out.println(queue.remove());
        System.out.println(queue.remove());
        System.out.println(queue.remove());
//        System.out.println(queue.remove());
    }
    private static void test1() {
        //抛出异常
        BlockingQueue queue = new ArrayBlockingQueue(3);
        queue.add("A");
        queue.add(1);
        queue.add(1);

//        queue.add(1);

        System.out.println(queue.remove());
        System.out.println(queue.remove());
        System.out.println(queue.remove());
//        System.out.println(queue.remove());
    }
}
